package freshmanspecial.mredrock.com.welcomefreshman.View;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import freshmanspecial.mredrock.com.welcomefreshman.Adapter.MyPagerAdapter;
import freshmanspecial.mredrock.com.welcomefreshman.Base.BaseActivity;
import freshmanspecial.mredrock.com.welcomefreshman.Fragment.TrainMienFragment;
import freshmanspecial.mredrock.com.welcomefreshman.Fragment.TrainTipFragment;
import freshmanspecial.mredrock.com.welcomefreshman.Presenter.DataPresenter;
import freshmanspecial.mredrock.com.welcomefreshman.Presenter.TrainPresenter;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by Administrator on 2017/8/9 0009.
 */

public class TrainView extends BaseActivity implements ITrainView {
    private ImageButton btn_backToMainView;
    private TextView text_title;
    private TrainPresenter presenter;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private MyPagerAdapter adapter;
    private List<Fragment> list;
    private String[] titles = {"军训贴士","军训风采"};

    @Override
    protected void initData() {
        presenter = new TrainPresenter(this);
        btn_backToMainView = $(R.id.btn_back);
        text_title = $(R.id.text_titlebar);
        text_title.setText("军训特辑");
        tabLayout = $(R.id.train_tab);
        viewPager = $(R.id.train_pager);
        adapter = new MyPagerAdapter(getSupportFragmentManager());
        list = new ArrayList<>();
        list.add(new TrainTipFragment());
        list.add(new TrainMienFragment());
        adapter.setTitles(titles);
        adapter.setFragments(list);
        viewPager.setOffscreenPageLimit(2);
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLayout,52,52);
            }
        });
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        setBackToMainView();
    }
    @Override
    public void setBackToMainView() {
        btn_backToMainView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                presenter.backToMainView();
            }
        });
    }
    @Override
    protected int getContentViewId() {
        return R.layout.special_2017_trainview;
    }
}
